package com.chenchao.thread;

/**
 * @encoding : UTF-8
 * @Time : 2020/11/17 19:40
 * @Author : Chen Chao
 * @File : javaSE.com.chenchao.javathread.Test11.java
 * @Software : IntelliJ IDEA
 * @since : 1.8
 * 线程礼让，礼让不一定成功
 */
public class Test11 {
    public static void main(String[] args) {
        new Thread(new Yield1(),"线程A").start();
        new Thread(new Yield1(),"线程B").start();
    }
}
class Yield1 implements Runnable{

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName()+"开始执行！");
        Thread.yield();//礼让不一定成功，cup可能让你出去再进来
        System.out.println(Thread.currentThread().getName()+"结束执行！");
    }
}
class Yield2 implements Runnable{

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName()+"开始执行！");
        System.out.println(Thread.currentThread().getName()+"结束执行！");
    }
}
